from aiogram import BaseMiddleware
from aiogram import types

from tg_bot.config import Config


class ConfigSetter(BaseMiddleware):
    """
    Добавляем в **kwargs главный конфиг и дату из state.
    """
    def __init__(self, config: Config):
        self.config = config

    async def __call__(self, handler, event: types.Update, data: dict):
        state = data.get('state')
        state_data = await state.get_data()
        data['config'] = self.config
        data['data'] = state_data
        await handler(event, data)
